local que_xueyuan = fk.CreateSkill {
    name = "que_xueyuan",
    anim_type = "offensive",
    dynamic_desc = function(self, player)
        return "que_xueyuan_ewai:" .. 1 + player:getMark("que_xueyuan")
    end,
}
Fk:loadTranslationTable {
    ["que_xueyuan"] = "雪鸢",
    [":que_xueyuan"] = "其他角色获得你的牌，或你获得其他角色的牌后，你可以获得其区域内的1张牌。",

    [":que_xueyuan_ewai"] = "其他角色获得你的牌，或你获得其他角色的牌后，你可以获得其区域内的{1}张牌。",
}
que_xueyuan:addEffect(fk.AfterCardsMove, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(que_xueyuan.name) then
            for _, move in ipairs(data) do
                if move.from == player and move.to and move.to ~= player and move.toArea == Card.PlayerHand and move.skillName ~= "que_xueyuan" then
                    return true
                end
                if move.to == player and move.from and move.from ~= player and move.skillName ~= "que_xueyuan" then
                    return true
                end
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local n = player:getMark("que_xueyuan")
        for _, move in ipairs(data) do
            if move.from == player and move.to and move.to ~= player and move.toArea == Card.PlayerHand and move.skillName ~= "que_xueyuan" then
                local cards = table.filter(move.to:getCardIds("hej"),
                    function(cid) return Fk:getCardById(cid):getMark("@@que_xingjiang-turn") == 0 end)
                local id = room:askToChooseCards(player, {
                    target = move.to,
                    min = 1,
                    max = 1 + n,
                    flag = { card_data = { { "que_xueyuan", cards } } },
                    skill_name = que_xueyuan.name,
                })
                room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, que_xueyuan.name, nil, true, player)
                -- room:addPlayerMark(player, "xueyuan", 1)
                -- if player:getMark("xueyuan") > 1 then
                --     room:addPlayerMark(player, "que_xueyuan", 1)
                --     room:setPlayerMark(player, "xueyuan", 0)
                -- end
            end
            if move.to == player and move.from and move.from ~= player and move.skillName ~= "que_xueyuan" then
                local cards = table.filter(move.from:getCardIds("hej"),
                    function(cid) return Fk:getCardById(cid):getMark("@@que_xingjiang-turn") == 0 end)
                local id = room:askToChooseCards(player, {
                    target = move.from,
                    min = 1,
                    max = 1 + n,
                    flag = { card_data = { { "que_xueyuan", cards } } },
                    skill_name = que_xueyuan.name,
                })
                room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, que_xueyuan.name, nil, true, player)
                -- room:addPlayerMark(player, "xueyuan", 1)
                -- if player:getMark("xueyuan") > 2 and player:getMark("que_xueyuan") == 0 then
                --     room:addPlayerMark(player, "que_xueyuan", 1)
                --     room:setPlayerMark(player, "xueyuan", 0)
                -- end
            end
        end
    end,
})

return que_xueyuan
